import { postDiscussApi, getDiscussApi,getItemByIdApi } from '../../api/discuss'

export default {
  namespaced: true,
  state: {
    discussList: [],
    itemId:{}
  },
  mutations: {
    SET_DISCUSS (state, discuss) {
      state.discussList = discuss
    },
    SET_ITEM_BY_ID(state,itemId){
      state.itemId=itemId
    }
  },
  actions: {
    async postDiscuss ({rootState }, { bdid, content,uid }) {
      await postDiscussApi({ bdid, content, uid: rootState.login.form.id })
      // console.log(rootState.login.form.id)
    },
    async getDiscuss ({ commit },res) {
      let r = await getDiscussApi({bdid:res.bdid})
      commit('SET_DISCUSS', r.data.data)
      // console.log(r.data)
      // console.log(bdid)
    },
    async getItemId({commit},id){
      let {data}=await getItemByIdApi({id})
      commit('SET_ITEM_BY_ID',data.data[0])
      // console.log(data.data[0])
    }
  },
  getters: {

  }
}